﻿using System.Collections.Generic;
using System.IO;

namespace Microsoft.WowAddonStudio.Project.Import
{
	/// <summary>
	/// Stores template files which have to be deleted after the
	/// import process is completed.
	/// </summary>
	public class TempFileContainer
	{
		private readonly List<string> paths;
		private static readonly TempFileContainer instance = new TempFileContainer();

		/// <summary>
		/// Gets the instance.
		/// </summary>
		/// <value>The instance.</value>
		public static TempFileContainer Instance
		{
			get { return instance; }
		}

		/// <summary>
		/// Private constructor.
		/// </summary>
		private TempFileContainer()
		{
			paths = new List<string>();
		}

		/// <summary>
		/// Adds the temp file path.
		/// </summary>
		/// <param name="path">The path.</param>
		public void AddTempFilePath(string path)
		{
			paths.Add(path);
		}

		/// <summary>
		/// Deletes the temp files.
		/// </summary>
		public void DeleteTempFiles()
		{
			foreach (string path in paths)
			{
				try
				{
					File.Delete(path);
				}
				catch
				{
					//Delete all files possible
				}
			}

			paths.Clear();
		}
	}
}